package org.duang.plugins;

import java.util.HashMap;
import java.util.Map;

import org.duang.config.Config;
import org.duang.db.Connection;
import org.duang.push.WebSocket;

/**
 * PushPlugin(基于netty开发)
 * @author laotang
 *
 */
public class PushPlugin implements IPlugin {

	private static final long PUSH_TIMEOUT = 1000 * 60 * 60 * 24;	//一天
	
//	public void start() throws Exception{
//		if(InstanceFactory.getAsyncContextQueue() == null ){
//			InstanceFactory.initAsyncContextQueue();
//			Config.setPushTimeout(PUSH_TIMEOUT);
//		}
//	}
//
//	public void stop() throws Exception{
//		for (Iterator<AsyncContext> it = InstanceFactory.getAsyncContextQueue().iterator(); it.hasNext();) {
//			it.next().complete();
//		}
//	}
	
	public void start() throws Exception{
		Map<String, String> optionMap = new HashMap<String,String>();
		optionMap.put(Connection.HOST_FIELD, Config.getWebSocketHost());
		optionMap.put(Connection.PORT_FIELD, Config.getWebSocketPort());
		WebSocket.getInstance().connect(optionMap);
	}

	public void stop() throws Exception{
		WebSocket.getInstance().close();
	}

}
